﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class FilterConfigHeaderBLL : IBaseInfo
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IFilterConfigHeaderDA FilterConfigDA = DataAccess.CreateFilterConfigHeaderDA();
        private static readonly IFilterConfigDetailDA FilterConfigDetailDA = DataAccess.CreateFilterConfigDetailDA();
        private PubParasInfo pubParasInfo;

        public FilterConfigHeaderBLL()
        {
            this.pubParasInfo = null;
        }

        public FilterConfigHeaderBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public FilterConfigHeaderBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string Delete(List<string> IDS)
        {
            return "";
        }

        public DataSet GetAllInfo()
        {
            return FilterConfigDA.GetAllFilterConfigHeader(this.dataBaseID[0]);
        }

        public object GetInfoByID(string id)
        {
            return FilterConfigDA.GetFilterConfigHeaderByID(id, this.dataBaseID[0]);
        }

        public DataSet GetInfoByQueryEntity(object obj)
        {
            FilterConfigHeaderQueryEntity filterConfigHeaderInfo = obj as FilterConfigHeaderQueryEntity;
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(filterConfigHeaderInfo.TableName))
            {
                sqlWhere.Add(" TABLE_NAME " + filterConfigHeaderInfo.TableName);
            }
            if (!string.IsNullOrEmpty(filterConfigHeaderInfo.Descr))
            {
                sqlWhere.Add(" DESCR " + filterConfigHeaderInfo.Descr);
            }
            if (!string.IsNullOrEmpty(filterConfigHeaderInfo.IsActive))
            {
                sqlWhere.Add(" IS_ACTIVE " + filterConfigHeaderInfo.IsActive);
            }
            if (!string.IsNullOrEmpty(filterConfigHeaderInfo.SystemCreated))
            {
                sqlWhere.Add(" SYSTEM_CREATED " + filterConfigHeaderInfo.SystemCreated);
            }
            return FilterConfigDA.GetFilterConfigHeaderByQueryList(sqlWhere, filterConfigHeaderInfo, this.dataBaseID[0]);
        }

        public string Insert(object obj)
        {
            return string.Empty;
        }

        public string Update(object obj)
        {
            return "";
        }
    }
}

